package com.esurvey.core;

public class Visitor {
	public static final String NIF_STRING_ASOCIATION = "TRWAGMYFPDXBNJZSQVHLCKE";
	private int id;
	private String NIF;
	private String name;
	
	public Visitor(String NIF, String name) throws Exception {
		this.setNIF(NIF);
		this.setName(name);
	}
	
	public Visitor(int id, String NIF, String name) throws Exception {
		this(NIF, name);
		this.setId(id);
	}

	public int getId() { return this.id; }
	
	public void setId(int id) {
		this.id = id;
	}

	public void setNIF(String NIF) throws Exception {
		if (NIF.length() != 0) {
			this.NIF = NIF;
		} else {
			throw new eSurveyException("Invalid visitor NIF: '"+NIF+"'");
		}
	}

	public String getNIF() {
		return NIF;
	}
	
	public String getName() { return this.name; }
	
	public void setName(String name) throws Exception {
		if (name.length() != 0) {
			this.name = name;
		} else {
			throw new eSurveyException("Invalid visitor name: '"+name+"'");
		}
	}
	
	/**
	  * ESPECIFICACIÓN: Devuelve un NIF completo a partir de un DNI. Es decir, devuelve un NIF
	  * a partir del DNI introducido como parámetro
	  **/
	  public static String letraDNI(int dni) {
		  return String.valueOf(dni) + NIF_STRING_ASOCIATION.charAt(dni % 23);
	  }
}
